﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace PROJECT_BOMBER.BLL
{
    public class ReboundCollision : CollisionStrategy
    {
        public override void Collision(ElementPhysique element2, ElementMove element)
        {
            #region Rebount character
            if (element2.IntersectPX(element))
            {

                float spaceXleft = element.Case.Right - element2.Case.Left; //TODO change positioncontrol
                float spaceXright = element2.Case.Right - element.Case.Left; //TODO change positioncontrol
                float spaceYtop = element.Case.Bottom - element2.Case.Top; //TODO change positioncontrol
                float spaceYbottom = element2.Case.Bottom - element.Case.Top; //TODO change positioncontrol
                string cote = "";

                if (spaceXleft >= 0 && element.Speed.X > 0 && spaceXleft < (uint)spaceYtop && spaceXleft < (uint)spaceYbottom) cote = "left";

                else if (spaceXright >= 0 && element.Speed.X < 0 && spaceXright < (uint)spaceYtop && spaceXright < (uint)spaceYbottom) cote = "right";

                else if (spaceYbottom >= 0 && element.Speed.Y < 0 && spaceYbottom < (uint)spaceXleft && spaceYbottom < (uint)spaceXright) cote = "bottom";

                else if (spaceYtop >= 0 && element.Speed.Y > 0 && spaceYtop < (uint)spaceXleft && spaceYtop < (uint)spaceXright) cote = "top";

                switch (cote)
                {
                    case "top":
                        element.Speed = new Vector2(element.Speed.X, (float)(-element.Speedmax.Y / 2.5));
                        element.Jump = 2;
                        element.Fly = false;
                        break;

                    case "bottom":
                        element.Speed = new Vector2(element.Speed.X, 0);
                        break;

                    case "right":
                        element.Speed = new Vector2(0, element.Speed.Y);
                        break;

                    case "left":
                        element.Speed = new Vector2(0, element.Speed.Y);
                        break;
                }
            }
            #endregion
        }

        public override void Collision(ElementMove element, ElementMove element2)
        {
        }
    }
}
